﻿using MediatR;
using Microsoft.AspNetCore.Server.HttpSys;
using SmartMedicalCare.API.Write.Applications.Commands.轮播图;
using SmartMedicalCare.Domain;
using SmartMedicalCare.ErronCode;
using SmartMedicalCare.Infrastructure.Implaction;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SmartMedicalCare.API.Write.Applications.CommandHandlers.轮播图
{
    public class AddCarouselCommandHandler : IRequestHandler<AddCarouselCommand, APIResult<int>>
    {
        private readonly IBaseRespository<CarouselModel> carRep;

        public AddCarouselCommandHandler(IBaseRespository<CarouselModel> carRep)
        {
            this.carRep = carRep;
        }

        public async Task<APIResult<int>> Handle(AddCarouselCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            result.code = ResultCode.添加成功;
            result.Message = ResultCode.添加成功.ToString();

            CarouselModel car = new CarouselModel();
            car.Title = request.Title;
            car.ImageUrl = request.ImageUrl;
            car.JumpUrl = request.JumpUrl;
            car.StartTime = DateTime.Now;
            car.EndTime = DateTime.Now;
            car.Status = request.Status;
            car.CreateTime = DateTime.Now;
            car.IsDeleted = false;
            car.Counts = request.Counts;
            car.CreateName = request.CreateName;
            await carRep.AddAsync(car);


            return await Task.FromResult(result);
        }
    }
}
